package appconfig

import (
	"github.com/spf13/viper"
	"log"
)

type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}

type Redis struct {
	Host     string
	Port     int
	Password string
}

type ALiYunSms struct {
	AccessKeyId     string
	AccessKeySecret string
	Endpoint        string
}

type AppConfig struct {
	Mysql
	Redis
	ALiYunSms
}

var AppCong AppConfig

func Init() {
	viper.SetConfigFile("../appconfig/config.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic("读取配置文件失败")
	}
	err = viper.Unmarshal(&AppCong)
	if err != nil {
		panic("解析配置文件失败")
	}
	log.Println("viper 动态获取数据库成功")
}
